/**
 * Copyright 2014-2015 www.fsfkj.com
 * All rights reserved.
 * 
 * @project
 * @author jipengfei
 * @version 1.0
 * @date 2015-10-20
 */
package com.eyaomall.wxmanage.common.helper;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.eyaomall.wxmanage.common.constants.CookieEnums;
import com.lycheeframework.core.common.cookie.CookieManager;
import com.lycheeframework.core.common.util.encrypt.MD5;
import com.lycheeframework.core.common.util.encrypt.SHA256;

public class UserHelper {

	/**
	 * 获取登陆的ID
	 * @return
	 */
	public static String getUserId() {
		
		return getValue(CookieEnums._EYAOMALL_EM_FORM_USER_ID.getName());
	}
	
//	/**
//	 * 获取登陆的角色ID
//	 * @return
//	 */
//	public static String getRoleId() {
//		
//		return getValue(CookieEnums._EYAOMALL_EM_FORM_ROLE_ID.getName());
//	}
	
	/**
	 * 获取登陆的账号
	 * @return
	 */
	public static String getAccount(){
		
		return getValue(CookieEnums._EYAOMALL_EM_FORM_ACCOUNT.getName());
	}
	
	/**
	 * 获取登陆的账号
	 * @return
	 */
	public static String getName(){
		
		return getValue(CookieEnums._EYAOMALL_EM_FORM_NAME.getName());
	}
	
//	/**
//	 * 获取登陆的账号
//	 * @return
//	 */
//	public static String getAccountType(){
//		
//		return getValue(CookieEnums._EYAOMALL_EM_FORM_TYPE.getName());
//	}
//	
	/**
	 * 加密密码明文
	 * @param passwd
	 * @return
	 */
	public static String getEntryPasswd(String passwd){
		passwd = SHA256.encrypt(passwd);
		
		return MD5.encryptMD5(passwd);
	}
	
	private static String getValue(String key) {
		HttpServletRequest request  = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		CookieManager cookie = new CookieManager(request);
		
		return cookie.getValue(CookieEnums._EYAOMALL_EM_FORM.getName(),key,true);
	}
	
	public static void main(String[] args) {
		System.out.println(getEntryPasswd("hello123"));
	}

	
}